<section class="content-header">
    <h1>
        <?php echo $header_text; ?>
    </h1>
    <ol class="breadcrumb">
        <li><a href="./"><i class="fa fa-dashboard"></i> Dashboard</a></li>
        <li class="active"><i class="fa fa-group"></i> <?php echo $header_text; ?></li>
    </ol>
</section>

<!-- Main content -->
<section class="content">
	<div class="action-btns">
		<?php if($this->checkUserRole('edit_'.$type, $_SESSION['internalKey'])) {?>
        <a href="javascript:;" id="saveResource" class="btn btn-success"><?php echo $this->_lang['save']; ?></a>
        <?php } ?>
        <?php if ($id && !empty($id) && $this->checkUserRole('delete_'.$type, $_SESSION['internalKey'])) {?>
        <a href="javascript:;" id="deleteResource" class="btn btn-danger"><?php echo $this->_lang['delete']; ?></a>
        <?php } ?>
        <a href="javascript:;" id="cancelResource" class="btn btn-warning"><?php echo $this->_lang['cancel']; ?></a>
    </div>

	<div class="box box-primary">
        <div class="box-header">
            <i class="fa fa-flask"></i>
            <h3 class="box-title"><?php echo $header_text; ?></h3>
        </div>
        <div class="box-body" id="editResource">
        	<input type="hidden" name="id" id="id" value="<?php echo isset($resource['id']) && is_numeric($resource['id']) ? $resource['id'] : ''?>" />
            <input type="hidden" name="type" id="type" value="<?php echo $type; ?>" />
            <table width="100%" cellpadding="5" cellspacing="0" border="0" class="resource-table">
                <tr>
                    <td width="200"><span class="warning"><?php echo $this->_lang["resource_name"]; ?>:</span></td>
                    <td><?php if ($type == 'chunk') { echo "{{"; } elseif ($type == 'snippet') { echo "[!"; } else { echo "&nbsp;&nbsp; "; } ?> <input type="text" name="name" id="name" class="inputBox" style="width:300px;" value="<?php echo isset($resource['name']) && !empty($resource['name']) ? $resource['name'] : ''; ?>" /> <?php if ($type == 'chunk') { echo "}}"; } elseif ($type == 'snippet') { echo "!]"; } ?>
                    <div id="uniqueResourceName" style="display:none;"></div></td>
                </tr>
                <tr>
                    <td width="200"><span class="warning"><?php echo $this->_lang["resource_description"]; ?>:</span></td>
                    <td>&nbsp;&nbsp; <input type="text" name="description" id="description" class="inputBox" style="width:300px;" value="<?php echo isset($resource['description']) && !empty($resource['description']) ? $resource['description'] : ''; ?>" /></td>
                </tr>
                <?php if ($type != 'template') { ?>
                <tr>
                    <td width="200"><span class="warning"><?php echo $this->_lang["resource_category"]; ?>:</span></td>
                    <td>&nbsp;&nbsp; <select name="section" id="section"><option value="0"><?php echo $this->_lang["no_category"]; ?></option>
                        <?php
                        $sqlS = "select * from ".$this->db."site_section order by sort_order,name ASC";
                        $rsS = $this->dbQuery($sqlS);
                        $limitS = $this->recordCount($rsS);
                        if($limitS>0){
                            for($i=0;$i<$limitS;$i++){
                                $row = $this->fetchRow($rsS);
                                if($row['id']==$resource['section']){ $selected=" selected='selected'"; }else{ $selected = ''; }
                                ?>
                                    <option value="<?php echo $row['id']; ?>"<?php echo $selected;?>><?php echo $row['name']; ?></option>
                                <?php
                            }
                        }
                        ?>
                    </select></td>
                </tr>
                <?php } ?>
                <tr>
                    <td width="200"><span class="warning"><?php echo $this->_lang["resource_locked"]; ?>:</span></td>
                    <td><span>&nbsp;&nbsp;</span><input name="locked" id="locked" type="checkbox" <?php echo $resource['locked']==1 ? "checked='checked'" : "" ;?> class="inputBox"> Only Administrators (Role ID 1) can edit</td>
                </tr>
                <tr>
                    <td width="200"><span class="warning"><?php echo $this->_lang["keep_editing"]; ?>:</span></td>
                    <td><span>&nbsp;&nbsp;</span><input name="stay" id="stay" type="checkbox" value="1" checked="checked" /></td>
                </tr>
            </table>
            <textarea name="resource_editor" id="resource_editor" rows="15" style="width:100%;"><?php
                switch($type) {
                    case 'template':
                        echo isset($resource['content']) && !empty($resource['content']) ? htmlspecialchars(stripslashes($resource['content'])) : '';
                    break;
                    default:
                        echo isset($resource['snippet']) && !empty($resource['snippet']) ? htmlspecialchars($resource['snippet']) : '';
                    break;
                }
                ?></textarea>
        </div>
    </div>
</section>
<?php if ($this->config['use_code_editor'] == 1) {?>
<script type="text/javascript">
    Etomite.usingEAEditor = true;
    editAreaLoader.init({
        id : "resource_editor"        // textarea id
        ,syntax: "<?php echo $syntax; ?>"            // syntax to be uses for highgliting
        ,start_highlight: <?php echo isset($this->config['code_highlight']) && $this->config['code_highlight'] ==1 ? true : false; ?>        // to display with highlight mode on start-up
        ,toolbar: "search, go_to_line, |, undo, redo, |, select_font,|, change_smooth_selection, syntax_selection, highlight, reset_highlight, |, help"
        ,syntax_selection_allow: "css,html,js,php,xml,sql"
        ,allow_resize: "both"
        ,allow_toggle: false
    });
</script>
<?php } ?>